/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-05-18
 * Time: 20:34
 */
public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val){
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    /**
     * 入队 : 尾插法
     */
    public void offer(int val){
        ListNode node =  new ListNode(val);
        if(head== null){
            head = node;
            last = node;
            return;
        }
        last.next = node;
        node.prev =last;
        last = node;



    }
    /**
     * 出队: 头删法
     */
    public int poll(){
        if(isEmpty()){
            return -1;
        }
        int oldVal = head.val;
        head = head.next;
        if(head!=null){
            head.prev = null ;
        }else{
            last = null;
        }

            return oldVal;
    }
    /**
     * 查看队首元素
     */
    public int peek(){
        if(isEmpty()){
            return -1;
        }

        return head.val;
    }
    /**
     * 判空
     */
    public boolean isEmpty(){
        return head == null ;

    }

}
